package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Jidi;
import com.example.exception.CustomException;
import com.example.service.JidiService;
import com.example.vo.JidiVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("jidiService")
public class JidiServiceImpl extends ServiceImpl<JidiDao, Jidi> implements JidiService {

    @Resource
    private JidiDao jidiDao;

    public Jidi add(Jidi jidi) {
		
	   //youquchong1
        jidi.setAddtime(new Date());
        jidiDao.insert(jidi);
        return jidi;
    }
	
	
	
    public void delete(Long id) {
        jidiDao.deleteById(id);
    }
	

    public void update(Jidi jidi) {
        //youquchong2
        jidiDao.updateById(jidi);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return jidiDao.daochuexcel();
    }

    @Override
    public Jidi findById(Integer id) {
        return jidiDao.selectById(id);
    }

    public JidiVo findPage(JidiVo jidiVo) {
        LambdaQueryWrapper<Jidi> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(jidiVo.getZuzhimingcheng()), Jidi::getZuzhimingcheng,jidiVo.getZuzhimingcheng());        wrapper.like(ObjectUtils.isNotEmpty(jidiVo.getHuodongneirong()), Jidi::getHuodongneirong,jidiVo.getHuodongneirong());        wrapper.like(ObjectUtils.isNotEmpty(jidiVo.getShangchuanchengyuanziliao()), Jidi::getShangchuanchengyuanziliao,jidiVo.getShangchuanchengyuanziliao());        wrapper.like(ObjectUtils.isNotEmpty(jidiVo.getZhaopian()), Jidi::getZhaopian,jidiVo.getZhaopian());        wrapper.like(ObjectUtils.isNotEmpty(jidiVo.getBeizhu()), Jidi::getBeizhu,jidiVo.getBeizhu());        
        Page<Jidi> page = new Page<>(jidiVo.getCurrent(),jidiVo.getCurrentNum());
        jidiDao.selectPage(page,wrapper);
        List<Jidi> jidis = page.getRecords();
        jidiVo.setList(jidis);
        jidiVo.setPages(page.getPages());
        jidiVo.setTotal(page.getTotal());
        jidiVo.setCurrent(page.getCurrent());
        jidiVo.setCurrentNum(page.getSize());
        return jidiVo;
    }

    @Override
    public void deleteList(List<Jidi> list) {
        List<Integer> ids =  list.stream().map(Jidi::getId).collect(Collectors.toList());
        jidiDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
